package com.han.practice;

import java.util.Scanner;


/**
 * pdd笔试-2
 * 输入一个字符串，"."表示空间 "#"表示墙壁 "D"代之人物位置，
 * 当玩家移动到某个位置时，如果该位置是 "."，获得一次穿墙技能，
 * 求解是否可以掏出隧道。
 */

public class Channel {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T=sc.nextInt();
        sc.nextLine();
        while(T-- > 0){
            int len = sc.nextInt();
            sc.nextLine();
            String s = sc.nextLine();

            boolean ans = check(s);
            System.out.println(ans ? "YES" : "NO");
        }

    }
    public static boolean check(String s){
        int loc = 0;
        int len = s.length();
        for(int i=0; i<len; i++) if(s.charAt(i) == 'D') loc = i;

        boolean skill = false;

        if(loc <= 0 || loc >= (len-1)) return true;
        if(s.charAt(loc-1) == '#' && s.charAt(loc+1) == '#' && !skill) return false;

        boolean left = stepTo(s, loc, -1, skill);
        boolean right = stepTo(s, loc, 1, skill);

        return left ||  right;
    }
    public static boolean stepTo(String s, int loc, int step, boolean skill){
        int len = s.length();
        if(loc <= 0 || loc >= (len-1)) return true;

        if(s.charAt(loc + step) == '#'){
            if(s.charAt(loc-step) == '.') skill = true;
            if(skill){
                loc += step;
                while(loc<len && loc>0 && s.charAt(loc) == '#') loc += step;
                skill = false;
            }else return false;
        }else {
            loc += step;
            skill = true;
        }
        return stepTo(s, loc, step, skill);
    }

    /**
     * 递归
     * 错误思路，容易栈溢
     */
    public static boolean check(String s, int loc, int step, boolean skill){
        int len = s.length();
        if(step > len) return false;
        step++;

        if(loc == 0 || loc == (len)) return true;

        if(s.charAt(loc-1) == '#' && s.charAt(loc+1) == '#' && !skill) return false;

        // left
        int leftLoc = loc;
        boolean leftSkill = skill;
        if(s.charAt(leftLoc-1) == '#'){
            if(leftSkill){
                leftLoc--;
                while(leftLoc>=0 && s.charAt(leftLoc) == '#') leftLoc--;
                leftSkill = false;
            }
        }else{
            leftLoc--;
            leftSkill = true;
        }
        boolean left = check(s, leftLoc, step, leftSkill);

        // right
        int rightLoc = loc;
        boolean rightSkill = skill;
        if(s.charAt(rightLoc+1) == '#'){
            rightLoc++;
            if(rightSkill){
                while(rightLoc<len && s.charAt(rightLoc) == '#') {
                    rightLoc++;
                }
                rightSkill = false;
            }
        }else{
            rightLoc++;
            rightSkill = true;
        }
        boolean right = check(s, rightLoc, step, rightSkill);

        if(left || right) return true;
        else return false;
    }

}
